<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8" />
    <title>修改密码</title>
    <link rel="icon" href="${pageContext.request.contextPath}/layui/images/favicon.ico">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layuimini.css?v=2.0.4.2" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/themes/default.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style>
        /* 基本信息*/
        #userPwdForm .layui-form-item {
            margin-bottom: 25px;
        }
        .layui-col-md9{
            width: 50%;
        }
        .layui-form{
            width: 600px;
        }
        .layui-form-label{
            width: 130px;
        }
        .layui-input-block{
            margin-left: 160px;
        }
    </style>
</head>
<body onscroll="layui.admin.hideFixedEl();" class="theme-pink close-footer">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-sm12 layui-col-md9">
            <div class="layui-card">
                <div class="layui-tab layui-tab-brief" lay-filter="userPwd">
                    <ul class="layui-tab-title">
                        <li class="layui-this" style="margin: 0 auto;">修改密码</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <form class="layui-form" id="userPwdForm" lay-filter="userPwdForm"
                                  style="max-width: 400px;padding: 25px 10px 0 0;">
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">请输入新密码:</label>
                                    <div class="layui-input-block">
                                        <input type="password" name="newPassword" required
                                               lay-verify="required" placeholder="请输入新密码" autocomplete="off"
                                               class="layui-input">
                                        <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">请输入确认密码:</label>
                                    <div class="layui-input-block">
                                        <input type="password" name="rePassword" required
                                               lay-verify="required" placeholder="请输入确认密码" autocomplete="off"
                                               class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-filter="userPwdSubmit" lay-submit style="background-color: #009688;">修改密码
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/layui/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/layui/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(['layer', 'form', 'element'], function() {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;

        /* 监听表单提交 */
        form.on('submit(userPwdSubmit)', function(data) {
            data = data.field;
            if (data.newPassword.length < 6 | data.newPassword.length > 16 ){
                layer.msg('密码长度在6~16个字符');
                return false;
            }
            if (data.newPassword != data.rePassword) {
                layer.msg('两次新密码输入不一致');
                return false;
            }
            //发送ajax修改
            $.ajax({
                url: '${pageContext.request.contextPath}/admin/employee/updatePwd',
                data: data,
                dataType: 'json',
                type: 'post',
                success: function (res) {
                    if(res.success){
                        layer.msg(res.message,{icon: 6},function () {
                            window.location.reload();
                        })
                    }else{
                        layer.msg(res.message,{icon: 5})
                    }
                },
                error: function () {
                    layer.msg("请求失败");
                }
            })
            return false;
        });

    });
</script>
</body>
</html>